package com.gwd.task.model;

import lombok.Getter;
import lombok.Setter;

/**
 * @author zhiyongming
 * @date 2020/11/9 17:04
 */
@Getter
@Setter
public class CallResultMsg<T> {
    private boolean result;
    private int code;
    private String message;
    private T data;

    public CallResultMsg(boolean result, CodeAndMsg msg, T data) {
        this.result = result;
        this.code = msg.getCode();
        this.message = msg.getMsg();
        this.data = data;
    }

    public CallResultMsg(boolean result, CodeAndMsg msg, String message, T data) {
        this.result = result;
        this.code = msg.getCode();
        this.message = message;
        this.data = data;
    }

    public static CallResultMsg<?> success() {
        return new CallResultMsg<>(true, CodeAndMsg.SUCCESS, null);
    }

    public static CallResultMsg<?> success(Object data) {
        return new CallResultMsg<>(true, CodeAndMsg.SUCCESS, data);
    }

    public static CallResultMsg<?> Unauthorized() {
        return new CallResultMsg<>(false, CodeAndMsg.Unauthorized, "认证错误",null);
    }

    public static CallResultMsg<?> LoginFail() {
        return new CallResultMsg<>(false, CodeAndMsg.Unauthorized, "账号密码错误",null);
    }

    public static CallResultMsg<?> UserDisabled() {
        return new CallResultMsg<>(false, CodeAndMsg.Unauthorized, "账号被禁用",null);
    }

    public static CallResultMsg<?> Fail(String message) {
        return new CallResultMsg<>(false, CodeAndMsg.METHOD_FAIL, message, null);
    }

    public static CallResultMsg<?> Fail() {
        return new CallResultMsg<>(false, CodeAndMsg.METHOD_FAIL, null);
    }

    public static CallResultMsg<?> Error(String message) {
        return new CallResultMsg<>(false, CodeAndMsg.SERVER_ERROR, message, null);
    }

    public static CallResultMsg<?> Error() {
        return new CallResultMsg<>(false, CodeAndMsg.SERVER_ERROR, null);
    }
}